﻿using System;
using Newtonsoft.Json;
using BLL.Access;
using System.Web;
using System.Data;

namespace Web.ashx.QSSFZW
{
    /// <summary>
    /// HuiGuanTF 的摘要说明
    /// </summary>
    public class HuiGuanTF : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            // context.Response.Write("Hello World");
            string op = context.Request["op"];
            SpHelper _sphelper = new SpHelper();
            if (op == "HGTF")
            {
                int y = int.Parse(context.Request["y"]);
                DataTable dt = _sphelper.P_DXSSF_HGTF(y, 0, 0).Tables[0];
                context.Response.Write(JsonConvert.SerializeObject(dt));
            }
            else if (op == "SXSJ")//刷新数据
            {
                int y = int.Parse(context.Request["y"]);
                DataTable dt = _sphelper.P_DXSSF_HGTF2(y, "", 1).Tables[0];
                string res = "";
                if (dt != null && dt.Rows.Count > 0)
                {
                    res = dt.Rows[0][0].ToString();
                }
                context.Response.Write(res);
            }
            else if (op == "YHSJ")//用户数据
            {
                int y = int.Parse(context.Request["y"]);
                DataTable dt = _sphelper.P_DXSSF_HGTF2(y, "", 2).Tables[0];
                //string res = "";
                //if (dt != null && dt.Rows.Count > 0)
                //{
                //    res = dt.Rows[0][0].ToString();
                //}
                context.Response.Write(JsonConvert.SerializeObject(dt));
            }
            else if (op == "JSJ")//井数据
            {
                int y = int.Parse(context.Request["y"]);
                string yhh = context.Request["yhh"];
                DataTable dt = _sphelper.P_DXSSF_HGTF2(y, yhh, 3).Tables[0];
                //string res = "";
                //if (dt != null && dt.Rows.Count > 0)
                //{
                //    res = dt.Rows[0][0].ToString();
                //}
                context.Response.Write(JsonConvert.SerializeObject(dt));
            }
            else if (op == "SAVE1")
            {
                int y = int.Parse(context.Request["y"]);
                string userid = context.Request["userid"];
                string jbh = context.Request["jbh"] != "" ? context.Request["jbh"] : null;
                string hgjh = context.Request["hgjh"]!= "" ?context.Request["hgjh"]: null;
                string csnl = context.Request["csnl"] != "" ? context.Request["csnl"] : null;
                string result = "";
                _sphelper.P_QSSF_SAVEHGTF(1, y, userid, jbh, hgjh, csnl, null, null, null, null, null, null, null, out result);
                context.Response.Write(result);
            }
            else if (op == "SAVE2")
            {
                int y = int.Parse(context.Request["y"]);
                string userid = context.Request["userid"];
                string yhh = context.Request["yhh"];
                string hgdj = context.Request["hgdj"]!= "" ?context.Request["hgdj"]: null;
                string wtsf = context.Request["wtsf"]!= "" ?context.Request["wtsf"]: null;
                string ytsf = context.Request["ytsf"]!= "" ?context.Request["ytsf"]: null;
                string ytsf2 = context.Request["ytsf2"] != "" ? context.Request["ytsf2"] : null;
                string yhzh = context.Request["yhzh"] != "" ? context.Request["yhzh"] : null;
                string khyh = context.Request["khyh"] != "" ? context.Request["khyh"] : null;
                string result = "";
                _sphelper.P_QSSF_SAVEHGTF(2, y, userid, null, null, null, yhh, hgdj, wtsf, ytsf, ytsf2, yhzh, khyh, out result);
                context.Response.Write(result);
            }
            else if (op == "SAVEFPJL")//保存发票打印记录
            {
                int userid = Convert.ToInt32(context.Request["userid"]);
                string yhhs = context.Request["yhhs"];
                int zt = Convert.ToInt32(context.Request["zt"]);
                DataTable dt = _sphelper.P_QSSF_GETHGTFSJ(3, yhhs, zt, userid).Tables[0];
                string result = dt.Rows.Count > 0 ? dt.Rows[0][0].ToString() : "";
                context.Response.Write(result);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}